package com.example.controller;

import com.example.domain.MeetingSheet;
import com.example.service.IMeetingSheetService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议签到Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/sheet")
public class MeetingSheetController extends BaseController
{
    @Autowired
    private IMeetingSheetService meetingSheetService;

    /**
     * 查询会议签到列表
     */
    @RequiresPermissions("day:sheet:list")
    @GetMapping("/list")
    public TableDataInfo list(MeetingSheet meetingSheet)
    {
        startPage();
        List<MeetingSheet> list = meetingSheetService.selectMeetingSheetList(meetingSheet);
        return getDataTable(list);
    }

    /**
     * 导出会议签到列表
     */
    @RequiresPermissions("day:sheet:export")
    @Log(title = "会议签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingSheet meetingSheet)
    {
        List<MeetingSheet> list = meetingSheetService.selectMeetingSheetList(meetingSheet);
        ExcelUtil<MeetingSheet> util = new ExcelUtil<MeetingSheet>(MeetingSheet.class);
        util.exportExcel(response, list, "会议签到数据");
    }

    /**
     * 获取会议签到详细信息
     */
    @RequiresPermissions("day:sheet:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingSheetService.selectMeetingSheetById(id));
    }

    /**
     * 新增会议签到
     */
    @RequiresPermissions("day:sheet:add")
    @Log(title = "会议签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingSheet meetingSheet)
    {
        return toAjax(meetingSheetService.insertMeetingSheet(meetingSheet));
    }

    /**
     * 修改会议签到
     */
    @RequiresPermissions("day:sheet:edit")
    @Log(title = "会议签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingSheet meetingSheet)
    {
        return toAjax(meetingSheetService.updateMeetingSheet(meetingSheet));
    }

    /**
     * 删除会议签到
     */
    @RequiresPermissions("day:sheet:remove")
    @Log(title = "会议签到", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meetingSheetService.deleteMeetingSheetByIds(ids));
    }
}
